<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>旅游网</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" th:href="@{layui/css/layui.css(t=2)}" media="all">
    <link rel="stylesheet" th:href="@{febs/css/febs.css(t=2)}" media="all">
    <link rel="stylesheet" th:href="@{febs/css/login.css(t=2)}" media="all">
    <link rel="icon" th:href="@{febs/images/favicon.ico}" type="image/x-icon"/>
</head>
<body>

<div id="febs-login" lay-title="登录">
    <div class="login-wrap">
        <canvas width="1800" height="600" id="myCanvas" style="position: fixed"></canvas>
        <div class="layui-container">
            <div class="layui-col-xs12 layui-col-lg4 layui-col-lg-offset4 febs-tc">
                <div class="layui-logo"><span><b>旅游网</b> 管理</span></div>
            </div>
            <div class="layui-col-xs12 layui-col-lg4 layui-col-lg-offset4" id="login-div">
                <div class="layui-form" lay-filter="login-form" style="border-radius: 30px 30px 30px 30px;
                background:-webkit-repeating-linear-gradient(top,white,lightblue,white,#adc6ff)">
                    <div class="layui-anim layui-anim-upbit">
                        <ul class="login-type-tab">
                            <li class="active">Password</li>
                        </ul>
                        <div class="normal-login-form">
                            <div class="layui-form-item">
                                <label class="layui-icon label-icon layui-icon-username"></label>
                                <input type="text" name="username" lay-verify="required"
                                       placeholder="Your User ID" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-item password-block">
                                <label class="layui-icon label-icon layui-icon-password"></label>
                                <input type="password" name="password" lay-verify="required" minlength="6"
                                       maxlength="12"
                                       placeholder="Password" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-row">
                                    <div class="layui-col-xs7">
                                        <label class="layui-icon label-icon layui-icon-vercode"></label>
                                        <input type="text" maxlength="4" name="verifyCode" lay-verify="required"
                                               placeholder="Verification code" class="layui-input" autocomplete="off">
                                    </div>
                                    <div class="layui-col-xs5">
                                        <img class="codeimg" id="codeimg"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item" style="margin-top: -10px;">
                                <input type="checkbox" name="rememberMe" title="remember me" lay-skin="primary">
                            </div>
                            <div class="layui-form-item">
                                <button class="layui-btn layui-btn-normal layui-btn-fluid" lay-submit
                                        lay-filter="login-submit" id="login">
                                    <i style="display: none;"
                                       class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i>
                                    Login
                                </button>
                            </div>
                        </div>
                        <div class="layui-form-item febs-tr">
                            <a id="regist-href">Registered account</a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-col-xs12 layui-col-lg4 layui-col-lg-offset4 febs-hide" id="regist-div">
                <div class="layui-form" lay-filter="regist-form" style="border-radius: 30px 30px 30px 30px;
                 background:-webkit-repeating-linear-gradient(top,white,lightblue,white,#adc6ff)">
                    <div class="layui-anim layui-anim-upbit">
                        <ul class="login-type-tab">
                            <li class="active">Free Registration</li>
                        </ul>
                        <div class="normal-login-form">
                            <div class="layui-form-item">
                                <label class="layui-icon label-icon layui-icon-username"></label>
                                <input type="text" name="username" minlength="2" maxlength="10" lay-verify="range"
                                       placeholder="Phone number" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-item password-block">
                                <label class="layui-icon label-icon layui-icon-password"></label>
                                <input type="password" name="password" minlength="6" maxlength="12"
                                       lay-verify="range"
                                       placeholder="password" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-item password-block">
                                <label class="layui-icon label-icon layui-icon-password"></label>
                                <input type="password" name="passwordB" lay-verify="required"
                                       placeholder="Confirm password" autocomplete="off" maxlength="12" class="layui-input">
                            </div>

                            <div class="layui-form-item">
                                <button class="layui-btn layui-btn-normal layui-btn-fluid" lay-submit
                                        lay-filter="regist-submit" id="regist">
                                    <i style="display: none"
                                       class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i>
                                    Registered account
                                </button>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item febs-tr">
                        <a id="login-href">Exising account？Login now</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="loading" style="display: none">
    <div style="background-image: url(febs/images/eckarts/background.jpg);position: absolute; height: 100%; width: 100%">
        <fieldset class="layui-elem-field layui-field-title" style="margin: 100px;">
            <legend style="text-align: center;color: #00d57b;font-size: 32px;font-weight: bold;background-color: white">
                正在加载旅游网系统
            </legend>
        </fieldset>
        <hr class="layui-bg-orange">
        <div class="layui-progress layui-progress-big" lay-showpercent="true" lay-filter="demo">
            <div class="layui-progress-bar layui-bg-blue" lay-percent="0%"
                 style="background-image: url(febs/images/eckarts/map.png);"></div>
        </div>
        <hr class="layui-bg-orange">
    </div>
</div>
<script>
    let c = document.getElementById('myCanvas');
    let cxt = c.getContext('2d');
    let num = 100;//粒子数量
    let balls = [];

    for (let i = 0; i < num; i++) {
        //设置随机数（粒子横坐标，纵坐标，半径，水平移动速度，垂直移动速度）
        let startX = Math.random() * (c.width - 5) + 5;
        let startY = Math.random() * (c.height - 5) + 5;
        let radius = Math.random() * 2 + 1;
        let speedX = Math.random() * 2 - 1;
        let speedY = Math.random() * 2 - 1;//速度的方向(正负)大小都是随机的
        // let colour = `rgba(${Math.random() * 255},${Math.random() * 255},${Math.random() * 255},.7)`;
        balls.push({startX, startY, radius, speedX, speedY});//存入数组
    }

    function change(ball) {
        cxt.beginPath();//开始绘制粒子
        cxt.fillStyle = '#11EEEE';
        cxt.arc(ball.startX, ball.startY, ball.radius, 0, Math.PI * 2);
        cxt.fill();

        //粒子碰到画布边界会自动反弹
        ball.speedX *= (ball.startX + ball.radius) >= c.width || (ball.startX - ball.radius) <= 0 ? -1 : 1;
        ball.speedY *= (ball.startY + ball.radius) >= c.height || (ball.startY - ball.radius) <= 0 ? -1 : 1;

        ball.startX += ball.speedX;
        ball.startY += ball.speedY;
    }

    function move() {
        cxt.clearRect(0, 0, c.width, c.height);//清除画布
        for (let i = 0; i < num; i++) {
            change(balls[i]);
        }
    }

    //点与点之间划线，距离较小的连线，距离大的则不连
    function drawLines() {
        move();
        let long = 100;
        let newBalls = [];//设置新数组以便与其他粒子比较距离

        balls.forEach(function (ball) {//遍历数组
            for (let i = 0; i < num; i++) {
                newBalls[i] = balls[i];//赋值给新数组
                let disX = newBalls[i].startX - ball.startX;
                let disY = newBalls[i].startY - ball.startY;
                let dis = Math.sqrt(disX * disX + disY * disY);
                if (dis <= long) {
                    cxt.beginPath();
                    cxt.lineWidth = (long - dis) / long;
                    cxt.strokeStyle = `rgba(0, 0, 0, ${dis / long})`;
                    cxt.moveTo(newBalls[i].startX, newBalls[i].startY);
                    cxt.lineTo(ball.startX, ball.startY);
                    cxt.stroke();
                }
            }
            //添加鼠标事件
            c.onmousemove = function (ev) {
                ev = event || window.event;
                for (let i = 0; i < num; i++) {
                    let newX = newBalls[i].startX - ev.clientX;
                    let newY = newBalls[i].startY - ev.clientY;
                    let newDis = Math.sqrt(newX * newX + newY * newY);
                    if (newDis <= long) {//周围的点朝着鼠标方向移动
                        newBalls[i].startX -= newX * 0.04;
                        newBalls[i].startY -= newY * 0.04;
                    }
                }
            };
        });
    }
    setInterval(drawLines, 20);
</script>
<script th:src="@{layui/layui.js}"></script>
<script th:inline="javascript">
    var ctx = [[@{/}]];
        layui.extend({
            validate: './febs/lay/modules/validate'
        }).use(['form', 'layer', 'validate', 'element'], function (form, layer) {
            var $ = layui.jquery,
                validate = layui.validate,
                $view = $('#febs-login'),
                type = 'login',
                element = layui.element,
                $loginDiv = $view.find('#login-div'),
                $registDiv = $view.find('#regist-div');

            form.verify(validate);
            form.render();
            initCode();

            //提交登录表单
            form.on('submit(login-submit)', function (data) {
                var loading = $(this).find('.layui-icon');
                if (loading.is(":visible")) return;
                loading.show();
                $.post(ctx + 'login', data.field, function (r) {
                    if (r.code === 200) {
                        //触发事件
                        $('#febs-login').css({display: 'none'});
                        $('#loading').css({display: 'block'});
                        //模拟loading
                        let n = 0;
                        var timer = setInterval(function () {
                            n = n + Math.random() * 10 | 0;
                            if (n > 100) {
                                n = 100;
                                clearInterval(timer);
                                setTimeout(toIndex, 1000);
                            }
                            element.progress('demo', n + '%');
                        }, 100 + Math.random() * 10);
                    } else {
                        layer.msg(r.message);
                        loading.hide();
                        initCode();
                    }
                });
            });

            function toIndex() {
                location.href = ctx + 'index';
            }

            //提交注册表单
            form.on('submit(regist-submit)', function (data) {
                if (data.field.password !== data.field.passwordB) {
                    layer.msg('两次密码输入不一致！');
                    return;
                }
                var loading = $(this).find('.layui-icon');
                if (loading.is(":visible")) return;
                loading.show();
                $.post(ctx + 'regist', data.field, function (r) {
                    if (r.code === 200) {
                        layer.msg('注册成功，请登录');
                        loading.hide();
                        $view.find('#login-href').trigger('click');
                    } else {
                        layer.msg(r.message);
                        loading.hide();
                    }
                });
                return false;
            });

            function initCode() {
                $view.find('#codeimg').attr("src", ctx + "images/captcha?data=" + new Date().getTime());
            }

            $view.find('#codeimg').on('click', function () {
                initCode();
            });

            $view.find('#regist-href').on('click', function () {
                resetForm();
                type = 'regist';
                $loginDiv.hide();
                $registDiv.show();
            });

            $view.find('#login-href').on('click', function () {
                resetForm();
                type = 'login';
                $loginDiv.show();
                $registDiv.hide();
            });

            function resetForm() {
                $registDiv.find('input[name="username"]').val('')
                    .end().find('input[name="password"]').val('')
                    .end().find('input[name="passwordB"]').val('');

                $loginDiv.find('input[name="username"]').val('')
                    .end().find('input[name="password"]').val('')
                    .end().find('input[name="verifyCode"]').val('');
            }

            $(document).on('keydown', function (e) {
                if (e.keyCode === 13) {
                    if (type === 'login')
                        $view.find('#login').trigger("click");
                    if (type === 'regist')
                        $view.find('#regist').trigger("click");
                }
            });
        });
</script>
</body>
</html>